package com.ruoyi.csdn.controller;

import java.util.List;

import com.ruoyi.csdn.mapper.CsdnUserMapper;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.csdn.domain.CsdnArticle;
import com.ruoyi.csdn.service.ICsdnArticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CSDN文章发布Controller
 * 
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/csdn/article")
public class CsdnArticleController extends BaseController
{
    @Autowired
    private ICsdnArticleService csdnArticleService;



    /**
     * 查询CSDN文章发布列表
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsdnArticle csdnArticle)
    {
        startPage();
        List<CsdnArticle> list = csdnArticleService.selectCsdnArticleList(csdnArticle);
        return getDataTable(list);
    }

    /**
     * 查询CSDN 可用用户列表
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:list')")
    @GetMapping("/listcsdnuser")
    public AjaxResult listcsdnuser()
    {
       return AjaxResult.success(csdnArticleService.listcsdnuser());
    }

    /**
     * 导出CSDN文章发布列表
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:export')")
    @Log(title = "CSDN文章发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsdnArticle csdnArticle)
    {
        List<CsdnArticle> list = csdnArticleService.selectCsdnArticleList(csdnArticle);
        ExcelUtil<CsdnArticle> util = new ExcelUtil<CsdnArticle>(CsdnArticle.class);
        util.exportExcel(response, list, "CSDN文章发布数据");
    }

    /**
     * 获取CSDN文章发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(csdnArticleService.selectCsdnArticleById(id));
    }

    /**
     * 新增CSDN文章发布
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:add')")
    @Log(title = "CSDN文章发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsdnArticle csdnArticle)
    {
        return toAjax(csdnArticleService.insertCsdnArticle(csdnArticle));
    }

    /**
     * 修改CSDN文章发布
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:edit')")
    @Log(title = "CSDN文章发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsdnArticle csdnArticle)
    {
        return toAjax(csdnArticleService.updateCsdnArticle(csdnArticle));
    }

    /**
     * 删除CSDN文章发布
     */
    @PreAuthorize("@ss.hasPermi('csdn:article:remove')")
    @Log(title = "CSDN文章发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(csdnArticleService.deleteCsdnArticleByIds(ids));
    }
}
